﻿#include "accountdown.h"
#include "ui_accountdown.h"

#include <QDebug>
#include <QString>
#include <QDir>
#include <QDirIterator>
#include <QFileInfo>
#include <QFile>
#include <QGraphicsDropShadowEffect>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <accountdownitem.h>
#include <QEvent>
#include <QScrollBar>

accountDown::accountDown(SQLiteUtil* sQLiteUtil,QWidget *parent) :
    QWidget(parent),
    ui(new Ui::accountDown)
{
    ui->setupUi(this);
    fileOperator=new FileOperator(this);
    QGraphicsDropShadowEffect* mainShadow = new QGraphicsDropShadowEffect(this);
    mainShadow->setOffset(0, 1);
    mainShadow->setBlurRadius(10);
    mainShadow->setColor(QColor(200, 200, 200)); //
    this->setGraphicsEffect(mainShadow);

    QList<QVariantMap> list = sQLiteUtil->selectAllAccoutDown();
    for(auto it=list.begin();it!=list.end();it++)
    {
       QVariantMap row = *it;
       accountDownItem* adi=new accountDownItem(row["headImgUrl"].toString(),row["email"].toString(),row["userName"].toString());
       ui->scrollArea_Layout->addWidget(adi);
       item_num++;
       connect(adi,&accountDownItem::sendUserInfo,[this](QString account){
           emit sendUserInfo(account);
       });
       connect(adi,&accountDownItem::onClose,[this](){
           item_num--;
           if(item_num==0){

           }else if(item_num==1){
               ui->scrollArea->setMaximumHeight(70);
           }else{
               ui->scrollArea->setMaximumHeight(140);
           }
       });
    }

    if(item_num==0)
    {

    }else if(item_num==1)
    {
        ui->scrollArea->setMaximumHeight(70);
    }
    else
    {
        ui->scrollArea->setMaximumHeight(140);
    }
}

void accountDown::enterEvent(QEvent *event){
    QScrollBar *verticalScrollBar = ui->scrollArea->verticalScrollBar();
     verticalScrollBar->setStyleSheet("QScrollBar:vertical {width:8px; }");
    QWidget::enterEvent(event);
}

void accountDown::leaveEvent(QEvent *event){
    QScrollBar *verticalScrollBar = ui->scrollArea->verticalScrollBar();
    verticalScrollBar->setStyleSheet("QScrollBar:vertical {width:0px; }");
    QWidget::leaveEvent(event);
}


accountDown::~accountDown()
{
    delete ui;
}
